#include "resize_tool.h"

ResizeTool::ResizeTool(QWidget* parent): QFrame(parent), _isMouseDown(false)
{
    //appearance
    QPalette palette;
    QBrush brush(QColor(0, 85, 127, 255));
    brush.setStyle(Qt::SolidPattern);
    palette.setBrush(QPalette::Active, QPalette::Base, brush);
    palette.setBrush(QPalette::Active, QPalette::Window, brush);
    palette.setBrush(QPalette::Inactive, QPalette::Base, brush);
    palette.setBrush(QPalette::Inactive, QPalette::Window, brush);
    palette.setBrush(QPalette::Disabled, QPalette::Base, brush);
    palette.setBrush(QPalette::Disabled, QPalette::Window, brush);
    setPalette(palette);

    setAutoFillBackground(true);
    setCursor(QCursor(Qt::SizeFDiagCursor));
}

void ResizeTool::mousePressEvent(QMouseEvent *e)
{
    _lastPointMouseDown.setX(e->x());
    _lastPointMouseDown.setY(e->y());
    _isMouseDown = true;
}

void ResizeTool::mouseReleaseEvent(QMouseEvent *)
{
    _isMouseDown = false;
}

void ResizeTool::mouseMoveEvent(QMouseEvent *e)
{
    if (_isMouseDown)
    {
        emit needResize(e->x()-_lastPointMouseDown.x(),e->y()-_lastPointMouseDown.y());
    }
}
